package com.qlu.syq.util;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * @ClassName: DistanceUtil
 * @Description: TODO
 * @Author: ZPF
 * @Date: 2021/5/20 12:31
 **/
public class DistanceUtil {
    public static void main(String[] args) {
        System.out.println("经纬度距离计算结果：" + getDistance(116.823817, 36.562393, 116.817806, 36.564485) + "米");
    }

    public static double getDistance(double longitudeFrom, double latitudeFrom, double longitudeTo, double latitudeTo) {
        GlobalCoordinates source = new GlobalCoordinates(latitudeFrom, longitudeFrom);
        GlobalCoordinates target = new GlobalCoordinates(latitudeTo, longitudeTo);

        return new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target).getEllipsoidalDistance();
    }
}
